package com.dalin.platform.loa.action;

import java.util.ArrayList;
import java.util.List;

import com.dalin.common.utils.StringUtils;
import com.dalin.framework.action.StrutsTwoAction;
import com.dalin.platform.loa.LoaConst;
import com.dalin.platform.loa.condition.LoaDicItemCondition;
import com.dalin.platform.loa.model.LoaDicItemEntity;
import com.dalin.platform.loa.service.LoaService;
import com.dalin.platform.loa.vo.LoaDicItemTreeVo;
/*****************************************************************************
 * @content: 类信息                                                   *
 * @author : 那建林                                                                                                                                 *
 * @crtDate: 2010-06-07                                                     *
 * @modDate: 2010-06-07                                                     *
 * @version: 1.00                                                           *
 ****************************************************************************/
public class DicItemQueryAction extends StrutsTwoAction{
    private LoaService loaService; // 
    private Long typeId;
    private String parentId;
    
    public String execute()throws Exception {
        super.printInfo("", "===== this action begin");
        List<LoaDicItemTreeVo> rtnList = new ArrayList<LoaDicItemTreeVo>();
        LoaDicItemCondition cond = new LoaDicItemCondition();
        cond.setTypeId(typeId);
        cond.setParentId(getParentId());
        printObj(cond);
        List<LoaDicItemEntity> entyList = loaService
        		.queryListByCond(cond.prepareParams());
        LoaDicItemTreeVo vo = null;
        for (LoaDicItemEntity enty : entyList) {
        	vo = new LoaDicItemTreeVo();
        	vo.setPrimaryKey(enty.getItemId()+"");
        	vo.setHref(enty.getItemId()+"");
        	vo.setId(enty.getItemCode()+"");
        	vo.setText(enty.getItemName());
        	vo.setParentId(enty.getParentItemCode()+"");
        	vo.setRemark(enty.getRemark());
        	vo.setQtip("主&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;键:&nbsp;" + enty.getItemId()
        			   + "<br>细目代码:&nbsp;" + enty.getItemCode()
        			   + "<br>细目名称:&nbsp;" + enty.getItemName()
        			   + "<br>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:&nbsp;" + StringUtils.toString(enty.getRemark()));
        	
        	cond.setTypeId(typeId);
            cond.setParentId(enty.getItemCode());
        	List childrenList = loaService
        			.queryListByCond(cond.prepareParams());
        	if (StringUtils.isBlank(childrenList)) {
        		vo.setLeaf(true);
        	}
        	rtnList.add(vo);
        }
        setResContent(rtnList);
        super.printInfo("", "===== this action end");
        return null;

    }

    public LoaService getLoaService() {
        return loaService;

    }

    public void setLoaService(LoaService loaService) {
        this.loaService = loaService;

    }


	public String getParentId() {
		return StringUtils.isBlank(parentId) ? LoaConst.BASE_PARENT_ID + "" : parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	public Long getTypeId() {
		return typeId;
	}

	public void setTypeId(Long typeId) {
		this.typeId = typeId;
	}
}
